package com.lo.controller;

import com.github.pagehelper.PageInfo;
import com.lo.common.*;
import com.lo.entity.Teacher;
import com.lo.entity.User;
import com.lo.service.TeacherService;
import com.lo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("teacher")
public class TeacherController {
    @Autowired
    private TeacherService teacherService;
    @Autowired
    private AvatarInfo avatarInfo;
    @Autowired
    private CertificateInfo certificateInfo;


//    @RequestMapping("login")
//    public JsonResult login(String username,String password,HttpSession session){
//        if ((username==null||"".equals(username.trim()))||
//                (password==null||"".equals(password.trim()))){
//            return new JsonResult(3,"用户密码为空",null);
//        }
//        JsonResult result = teacherService.login(username,password);
//        Teacher teacher = (Teacher)result.getData();
//        session.setAttribute("teacher", teacher);
//        return result;
//    }

    //审核通过课程
//    @RequestMapping("myClassPage")
//    public JsonResult myClassPage(@RequestParam(value = "pageNum",required = false,defaultValue = "1")int pageNum,
//                                  @RequestParam(value = "pageSize",required = false,defaultValue = "9")int pageSize,
//                                  Long id,String search){
//        PageInfo pageInfo = teacherService.page(pageNum,pageSize,id, search);
//        JsonResult result = new JsonResult(0,"我的课程",pageInfo);
//        return result;
//    }

    //审核未通过课程
//    @RequestMapping("examiningCoursePage")
//    public JsonResult NotExamineCoursePage(@RequestParam(value = "pageNum",required = false,defaultValue = "1")int pageNum,
//                                           @RequestParam(value = "pageSize",required = false,defaultValue = "9")int pageSize,
//                                           Long id,String search){
//        PageInfo pageInfo = teacherService.NotExamineCoursePage(pageNum,pageSize,id,search);
//        JsonResult result = new JsonResult(0,"待审核课程",pageInfo);
//        return result;
//    }
//    @RequestMapping("selectTeacherMessage/{id}")
//    public JsonResult selectTeacherMessage(@PathVariable Long id){
//        JsonResult result = teacherService.selectTeacherMessage(id);
//        return result;
//    }

//    @RequestMapping("updateTeacherMessage")
//    public JsonResult updateTeacherMessage(Teacher teacher, MultipartFile avatarFile){
//        JsonResult selectResult = teacherService.selectTeacherMessage(teacher.getId());
//        Teacher teacherTemp =(Teacher) selectResult.getData();
//        if (teacherTemp.getAvatarUrl()!=null && avatarFile!=null){
//            FileDeleteUtils.delete(avatarInfo.getBasePath(),teacherTemp.getAvatarUrl());
//        }
//        if (avatarFile!=null){
//            JsonResult saveResult = FileUploadUtils.upload(avatarFile,avatarInfo.getBasePath(),"avatar");
//            teacher.setAvatarUrl((String) saveResult.getData());
//        }
//        return teacherService.updateTeacherMessage(teacher);
//    }
//    @RequestMapping("selectAllTeachers")
//    public JsonResult selectAllTeachers(@RequestParam(value = "pageNum",required = false,defaultValue = "1")int pageNum,
//                                     @RequestParam(value = "pageSize",required = false,defaultValue = "9")int pageSize,
//                                     String search){
//        PageInfo pageInfo = teacherService.selectAllTeachers(pageNum,pageSize,search);
//        JsonResult result = new JsonResult(0,"用户列表",pageInfo);
//        return  result;
//    }
    //传入信息设置封禁
//    @RequestMapping("setTeacherBanned/{id}")
//    public JsonResult setTeacherBanned(@PathVariable Long id){
//        return teacherService.setUserBanned(id);
//    }
//    //传入信息解封
//    @RequestMapping("setTeacherEnable/{id}")
//    public JsonResult setTeacherEnable(@PathVariable Long id){
//        return teacherService.setUserEnable(id);
//    }
    //获取教师总数
//    @RequestMapping("teacherCount")
//    public JsonResult teacherCount(){
//        return teacherService.teacherCount();
//    }
//    @RequestMapping("teacherOrdinaryCount")
//    public JsonResult teacherOrdinaryCount(){
//        return teacherService.teacherOrdinaryCount();
//    }
//    @RequestMapping("teacherVipCount")
//    public JsonResult teacherVipCount(){
//        return teacherService.teacherVipCount();
//    }
}
